package com.prs.crm.action.person;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;

import com.prs.crm.domain.person.Limit;
import com.prs.crm.service.person.LimitService;

public class LimitAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private Integer[] ids;
	private PaginationSupport pagination;
	private Limit limit;
	private LimitService limitService;
	public Integer[] getIds() {
		return ids;
	}
	public void setIds(Integer[] ids) {
		this.ids = ids;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public Limit getLimit() {
		return limit;
	}
	public void setLimit(Limit limit) {
		this.limit = limit;
	}
	public LimitService getLimitService() {
		return limitService;
	}
	public void setLimitService(LimitService limitService) {
		this.limitService = limitService;
	}
	
	@Action("listLimit")
	public String listLimit(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(Limit.class);
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.limitService.listByPage(criteria, pagination));
		return SUCCESS;
	}
	
	@Action("editLimit")
	public String editLimit(){
		if(ids!=null){
			this.limit=this.getLimitService().get(ids[0]);
		}
		return SUCCESS;
	}
	
	@Action(value="saveLimit",results={
			@Result(name="success",type="redirect",location="listLimit"),
			@Result(name="error",type="chain",location="editLimit")
	})
	public String saveLimit(){
		this.getLimitService().save(limit);
		return SUCCESS;
	}
	
	public String removeLimit(){
		if(ids==null){
			this.addActionError("请选择一行进行操作！");
			return ERROR;
		}
		this.getLimitService().batchRemove(ids);
		return SUCCESS;
	}
}
